#ifndef _WHILEEXPRESSION_HPP
#define _WHILEEXPRESSION_HPP

#include <string>
#include "Token.hpp"
#include "Expression.hpp"
#include "BlockStatement.hpp"

namespace ast {
	
	class WhileExpression : public Expression {

	public:
		WhileExpression(TOKEN token) {
			_token = token;
			_condition = nullptr;
			_body = nullptr;
		}

		virtual void ExpressionNode() override {}

		virtual string tokenLiteral() override {
			return _token._literal;
		}

		virtual string String() override {
			string out;
			string tab;
			for (int i = 0; i < _depth; i++) {
				out.append(tab);
			}
			out.append(_token._literal + " (");
			out.append(_condition->String());
			out.append(") {\n");
			_depth++;
			out.append(_body->String());
			for (int i = 0; i < _depth - 1; i++) {
				out.append(tab);
			}
			out.append("}");
			_depth--;
			return out;
		}

		virtual ~WhileExpression() {
			if (_condition != nullptr) {
				delete _condition;
				_condition = nullptr;
			}
			if (_body != nullptr) {
				delete _body;
				_body = nullptr;
			}
		}

	public:
		TOKEN _token;
		Expression* _condition{ nullptr };
		BlockStatement* _body{ nullptr };
	};
}

#endif // !_WHILEEXPRESSION_HPP
